package com.atguigu.spzx.service.product.service.impl;

import com.atguigu.spzx.service.product.service.CategoryService;
import com.atguigu.spzx.service.product.service.IndexService;
import com.atguigu.spzx.service.product.service.ProductSkuService;
import com.atguigu.spzx.model.entity.category.Category;
import com.atguigu.spzx.model.entity.product.ProductSku;
import com.atguigu.spzx.model.vo.h5.IndexVo;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * title:
 * author: zgl
 * date: 2024/1/15
 * description：
 */
@Service
public class IndexServiceImpl implements IndexService {
    @Autowired
    private CategoryService categoryService;

    @Autowired
    private ProductSkuService productSkuService;
    @Override
    public IndexVo getIndexData() {
        IndexVo indexVo = new IndexVo();
        List<Category> categoryList = categoryService.list(Wrappers.lambdaQuery(Category.class).eq(Category::getDeleted,0).eq(Category::getParentId,0)
                .orderByAsc(Category::getOrderNum));
        indexVo.setCategoryList(categoryList);

        List<ProductSku> productSkuList = productSkuService.list(Wrappers.lambdaQuery(ProductSku.class).eq(ProductSku::getStatus,1)
                .orderByDesc(ProductSku::getSaleNum).last("limit 8"));
        indexVo.setProductSkuList(productSkuList);
        return indexVo;
    }
}
